import { MessageProps, ElMessage } from 'element-plus'
import { ResultType } from '@xtail/result'

type ElMessageTypeWithoutType = Omit<Partial<MessageProps>, 'type'>

export const ElSuccessMessage_Name = 'ElSuccessMessage'

export const ElSuccessMessage = (options: ElMessageTypeWithoutType) => {
  ElMessage({
    type: 'success',
    ...options
  })
}

export const ElErrorMessage_Name = 'ElErrorMessage'

export const ElErrorMessage = (options: ElMessageTypeWithoutType) => {
  ElMessage({
    type: 'error',
    ...options
  })
}

export const ElInfoMessage_Name = 'ElInfoMessage'

export const ElInfoMessage = (options: ElMessageTypeWithoutType) => {
  ElMessage({
    type: 'info',
    ...options
  })
}

export const ElWarningMessage_Name = 'ElWarningMessage'

export const ElWarningMessage = (options: ElMessageTypeWithoutType) => {
  ElMessage({
    type: 'warning',
    ...options
  })
}

export const ElMessageByResult_Name = 'ElMessageByResult'

export const ElMessageByResult = (
  result: ResultType,
  options: Omit<ElMessageTypeWithoutType, 'message'> = {}
) => {
  if (result.status) {
    ElSuccessMessage({
      message: result.message,
      ...options
    })
  } else {
    ElErrorMessage({
      message: result.message,
      ...options
    })
  }
}
